<?php
	class Form extends Element{
		private $action = "";
		private $method = "";
		private $name = "";
		private $target = "";
		
		public function __construct($action, $method, $class){
			$this->action = $action;
			$this->method = $method;
			$this->class = $class;
		}
		
		public function getCode(){
			$this->code = "<table class='".$this->class."'><form action='".$this->action."' method='".$this->method."'>".$this->code."</form></table>";
			return $this->code;
		}
		
		public function setClass($class){
			$this->class = $class;
		}
		
		public function setAction($action){
			$this->action = $action;
		}
		
		public function setMethod($method){
			$this->method = $method;
		}
		
		public function setName($name){
			$this->name = $name;
		}
		
		public function setTarget($target){
			$this->target = $target;
		}
		
		public function getClass(){
			return $this->class;
		}
		
		public function getAction(){
			return $this->action;
		}
		
		public function getMethod(){
			return $this->method;
		}
		
		public function getName(){
			return $this->name;
		}
		
		public function getTarget(){
			return $this->target;
		}
		
		public function addLabel($name, $text){
			$this->code = $this->code."<tr><td><input name='".$name."' value='".$text."' style='visibility:hidden;'/></td></tr>";
		}
		
		public function addInput($text, $type, $name, $class, $value, $checked, $required){
			$this->code = $this->code ."<tr><td>";
			if($text != ""){
				$this->code = $this->code.$text."</td><td>";
			}
			$this->code = $this->code.$this->addInputTag($type, $name, $class, $value, $checked, $required)."</td></tr>";
		}
		
		public function addInputTag($type, $name, $class, $value, $checked, $required){
			$auxCode = "<input class='".$class."' type='".$type."' name='".$name."'";
			if($value != ""){
				$auxCode = $auxCode." value='".$value."'";
			}
			if($checked != ""){
				$auxCode = $auxCode." checked='".$checked."'";
			}
			if($required){
				$auxCode = $auxCode." required";
			}
			$auxCode = $auxCode." />";
			return $auxCode;
		}
		
		public function addTextArea($text, $class, $name, $value, $rows, $cols, $required){
			$this->code = $this->code."<tr>
											<td>".$text."</td>
											<td><textarea class=".$class." name=".$name."  cols=".$cols." rows=".$rows;
			if($required){
				$this->code = $this->code." required";
			}
			$this->code = $this->code.">".$value."</textarea></td>
										</tr>";
		}
		
		public function openSelect($text, $class, $name){
			$this->code = $this->code."<tr>
											<td>".$text."</td>
											<td><select class='".$this->class."' name='".$name."'>";
		}
		
		public function addOption($value, $text, $selected){
			$this->code = $this->code."<option value='".$value."'";
			if($selected){
				$this->code = $this->code." selected='selected'";
			}
			$this->code = $this->code.">".$text."</option>";
		}
		
		public function closeSelect(){
			$this->code = $this->code."</td></tr></select>";
		}
		
		public function openRadio($text){
			$this->code = $this->code."<tr>
											<td>".$text."</td>
											<td>";
		}
		
		public function addRadioOption($text, $name, $class, $value, $checked){
			$this->code = $this->code.$this->addInputTag("radio", $name, $class, $value, $checked, FALSE).$text."</br>";
		}
		
		public function closeRadio(){
			$this->code = $this->code."</td></tr>";
		}
		
		public function openCheckBox($text){
			$this->openRadio($text);
		}
		
		public function addCheckBox($text, $name, $class, $value, $checked){
			$this->code = $this->code.$this->addInputTag("checkbox", $name, $class, $value, $checked).$text."</br>";
		}
		
		public function closeCheckBox(){
			$this->closeRadio();
		}
	}
?>